package com.fuershiye.woman.monitor.utils;

import com.alibaba.fastjson2.JSON;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Map;

public class GsonUtils {

    /**
     * 不使用 Html Escaping 转码，避免 “=” 变成 “、u003d”
     */
    private static Gson gson = new GsonBuilder().disableHtmlEscaping().create();


    public static String toJson(Object input){
        if(null==input){
            return null;
        }
        return gson.toJson(input);
    }

    public static Object fromJson(String json, Class clazz){
        return gson.fromJson(json, clazz);
    }

    public static Map toMap(String json){
        return (Map)JSON.parse(json);
    }

}
